#include "rectangle.h"

rect::rect(const point &upper_left,int w, int h):shape(upper_left)
{
	m_width = w;
	m_hight = h;
}


void rect::Draw(HWND hwnd,int xt, int yt)
{
	if(xt<100)
		xt=100;
	else if(xt>700)
		xt=700;
	if(yt>600)
		yt=600;
	SetWidth(xt - m_pos.GetX());
	SetHight(yt - m_pos.GetY());

	HDC hdc = GetDC(hwnd);

	Rectangle(hdc,m_pos.GetX(),m_pos.GetY(),m_pos.GetX() + GetWidth(),m_pos.GetY() + GetHight());

	ReleaseDC (hwnd, hdc) ;
}

void rect::Draw(HWND hwnd)
{
	HDC hdc = GetDC(hwnd);

		Rectangle(hdc,m_pos.GetX(),m_pos.GetY(),m_pos.GetX() + GetWidth(),m_pos.GetY() + GetHight());

	ReleaseDC (hwnd, hdc) ;
}

void rect::Hide(HWND hwnd)
{
	
	HDC hdc = GetDC(hwnd);

		HPEN hPen = CreatePen (PS_SOLID,1,RGB(255,255,255));
		SelectObject (hdc, hPen);
		Rectangle(hdc,m_pos.GetX(),m_pos.GetY(),m_pos.GetX() + GetWidth(),m_pos.GetY() + GetHight());
		DeleteObject(hPen);

	ReleaseDC (hwnd, hdc) ;
}


bool rect::operator==(const rect &right) const
{
	if(!(m_pos == right.m_pos))
		return false;
	if(m_width != right.GetWidth() || m_hight != right.GetHight())
		return false;

	return true;
}

const rect& rect::operator =(const rect &right)
{
	if(this != &right)
	{
		m_pos = right.m_pos;
		SetWidth(right.GetWidth());
		SetHight(right.GetHight());
	}

	return *this;
}

ostream& operator<<(ostream &output,rect r)
{
	output << "pos = " << r.m_pos << "," << "width = " <<r.m_width << "," << "hight = " << r.m_hight << endl;

	return output;
}